/**
 * @author: shiding
 * @data: 2022/5/19 22:28
 **/
public class RemoveElement {

    public static void main(String[] args) {
        int arr[] = {0,1,2,2,3,0,4,2};
        int i = removeElement(arr, 2);
        System.out.println(i);
    }

    /**
     * 移除元素
     * @param nums
     * @param val
     * @return
     */
    public static int removeElement(int[] nums, int val) {
        if (null == nums) {
            return 0;
        }
        int fast = 0, slow = 0;
        while (fast < nums.length) {
            if (nums[fast] != val) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }

}
